<template>
    <section>
        <a-button class="mr20" type="danger" @click="deletefenzu"
            >删除分组</a-button
        >
        <a-button class="mr20" type="primary" @click="showqxszpop">创建分组</a-button>
        <template>
            <a-modal
                :visible="qxvisible"
                :footer="null"
                okText="确认"
                @cancel="cancelform"
                :maskClosable="false"
            >
                <a-form-model
                    ref="qxruleForm"
                    v-if="qxvisible"
                    layout="vertical"
                    :rules="qxrules"
                    :model="authGroupInfo"
                >
                    <a-form-model-item label="分组名称" prop="roleName">
                        <a-input v-model="authGroupInfo.roleName" />
                    </a-form-model-item>
                    <a-form-model-item label="分组编码" prop="roleCode">
                        <a-input
                            :disabled="editflag"
                            v-model="authGroupInfo.roleCode"
                        />
                    </a-form-model-item>
                    <a-form-model-item label="分组权限" prop="operCodeList"
                        >
                        <a-checkbox-group
                            @change="onChange"
                            v-model="authGroupInfo.operCodeList"
                        >
                            <a-checkbox
                                v-for="(item, index) in allAuthList"
                                :key="index"
                                :value="item.operateCode"
                            >
                                {{ item.operateName }}
                            </a-checkbox>
                        </a-checkbox-group>
                        <!-- <a-checkbox-group style='display:block;margin-bottom:10px'>
                            事实大屏查看权限:<br>
                            <a-checkbox>事实大屏查看权限</a-checkbox>
                        </a-checkbox-group>
                        <a-checkbox-group style='display:block;margin-bottom:10px'>
                            地图调度:<br>
                            <a-checkbox>调度组管理</a-checkbox>
                            <a-checkbox>一键呼叫</a-checkbox>
                            <a-checkbox>任务派发</a-checkbox>
                            <a-checkbox>一键对讲</a-checkbox>
                            <a-checkbox>发言</a-checkbox>
                            <a-checkbox>电子围栏</a-checkbox>
                        </a-checkbox-group>
                        <a-checkbox-group style='display:block;margin-bottom:10px'>
                            会议监控:<br>
                            <a-checkbox>会议组管理</a-checkbox>
                            <a-checkbox>发起会议</a-checkbox>
                        </a-checkbox-group>
                        <a-checkbox-group style='display:block;margin-bottom:10px'>
                            事件管理:<br>
                            <a-checkbox>新增事件</a-checkbox>
                            <a-checkbox>处理事件</a-checkbox>
                            <a-checkbox>上报事件</a-checkbox>
                            <a-checkbox>查询事件</a-checkbox>
                        </a-checkbox-group>
                        <a-checkbox-group style='display:block;margin-bottom:10px'>
                            设置:<br>
                            <a-checkbox>调度台添加</a-checkbox>
                            <a-checkbox>人员管理</a-checkbox>
                            <a-checkbox>权限设置</a-checkbox>
                            <a-checkbox>管理员创建</a-checkbox>
                            <a-checkbox>运营商创建</a-checkbox>
                            <a-checkbox>人员审核</a-checkbox>
                            <a-checkbox>修改密码</a-checkbox>
                        </a-checkbox-group> -->
                    </a-form-model-item>
                    <a-form-model-item :wrapper-col="{ span: 12, offset: 20 }">
                        <a-button type="primary" @click="addqx">保存</a-button>
                    </a-form-model-item>
                </a-form-model>
            </a-modal>
        </template>
    </section>
</template>
<script>
export default {
    props: {
        qxvisible: {
            type: Boolean,
            default: true,
        },
        editflag: {
            type: Boolean,
            default: false,
        },

        authGroupInfo: {
            type: Object,
            default: function () {
                return {};
            },
        },
    },
    data() {
        return {
            //权限设置

            allAuthList: [],
            authGroups: [],
            authListGroupItem: [],
            authListGroupItemselect: [],
            selectflag: true,
            delcheckbox: [],
            editcode: "",

            qxrules: {
                roleName: {
                    required: true,
                    message: "分组名称不能为空",
                },
                roleCode: {
                    required: true,
                    message: "分组编码不能为空",
                },
                operCodeList: {
                    required: true,
                    message: "分组权限不能为空",
                },
            },
        };
    },

    mounted() {
        //权限设置
        this.queryAllOperatorInfos();
        this.queryOwerOperatorGrop();
    },
    methods: {
        //权限设置
        showqxszpop() {
            this.$emit('showqxszpop')
            // this.qxvisible = true;
        },
        deletefenzu() {
            this.$emit("deletefenzu");
        },
        // 判断是否有当前权限
        queryOwerOperatorGrop() {
            this.$post("/exter/manage/queryOwerOperatorGrop", {}).then(
                (result) => {
                    this.authGroups = result.buss || [];
                    if (this.authGroups.length > 0) {
                        this.lookItemGroupAuth(this.authGroups[0]);
                        this.editcode = this.authGroups[0].roleCode;
                    }
                }
            );
        },
        lookItemGroupAuth(item) {
            this.curSelectAuthGroup = item.roleCode;
            this.catOperatorGrop({
                paramVar: item.roleCode,
            });
            this.editcode = item.roleCode;
            console.log(this.editcode);
        },
        catOperatorGrop(obj) {
            this.$post("/exter/manage/catOperatorGrop", obj).then((result) => {
                console.log(result);
                this.authListGroupItemselect = result.buss.operCodeList;
            });
        },
        onChange(val) {
            console.log(val);
            this.authGroupInfo.operCodeList = val;
        },
        // 查询全部权限
        queryAllOperatorInfos() {
            this.$post("/exter/manage/queryAllOperatorInfos", {}).then(
                (result) => {
                    console.log(result);
                    this.allAuthList = result.buss || [];
                }
            );
        },

        addqx() {
            this.authGroupInfo.addFlag = this.editflag ? 0 : 1;
            this.$refs["qxruleForm"].validate((valid) => {
                if (valid) {
                    this.$post(
                        "/exter/manage/setOperatorGrop",
                        this.authGroupInfo
                    ).then(() => {
                        this.qxvisible = false;
                        this.$emit("addqx");
                    });
                }
            });
        },

        cancelform() {
            this.$emit("cancelform");
        },
    },
};
</script>


